/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package 线程安全.线程安全单例懒汉;
/**
 * @description 线程安全的单例设计模式懒汉实现
 *
 * @author 俊昭
 * @date 2022/4/13
*/
public class BankTest {
    public static void main(String[] args) {

    }
}
class Bank{
    private Bank(){

    }
    private static Bank instance =null;


//    public static synchronized Bank getInstance(){ 同步方法
//
//        if (instance== null){
//            instance = new Bank();
//
//        }
//        return instance;
//    }
    public static  Bank getInstance(){// 同步代码块 加锁！，妙~
        if (instance==null){
            synchronized(Bank.class){
                if (instance== null){
                    instance = new Bank();
                }
            }
        }
        return instance;
    }
}